//
//  WebSockerManager.m
//  VoiceLive
//
//  Created by 凸阿滨 on 2017/10/20.
//  Copyright © 2017年 WB. All rights reserved.
//

#import "WebSockerManager.h"

@implementation WebSockerManager


-(void)webSocketDidOpen:(SRWebSocket *)webSocket{
    
    NSLog(@"WebSocket DidOpen");
    
//    [webSocket send:jsonString];//打开socket后根据后端要求传入字典字符串
}
- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message{
    
    //socket接收到信息后通过代理传给外部使用
    
//    [self.delegate getMessageFormSocket:dic];
    
}


-(void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean{
    
    NSLog(@"WebSocket closed");
    
}


-(void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error{
    
    NSLog(@":( Websocket Failed With Error %@", error);
    
}



- (void)WithIP:(NSString *)URLIP{
    _webSocket.delegate = nil;
    
    [_webSocket close];
    
    NSString *urlStr = [NSString stringWithFormat:@"%@", URLIP];
    
    NSURL *url = [NSURL URLWithString:urlStr];
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
}
//拿到URL后可以打开webSocket

- (void)openSocket {
    
    [_webSocket open];
    
}
//退出页面时记得关闭webSocket

- (void)closeSocket {
    
    self.webSocket.delegate = nil;
    
    [self.webSocket close];
    
    self.webSocket = nil;
    
}
//外部聊天发送消息给webSocket

- (void)sendTalkMessage:(NSString *)message{
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    
    dic = [@{ @"content":message} mutableCopy];
    
//    [self sendMessage:dic];
    
}

@end
